﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using umbraco.interfaces;
using System.Web.UI;
using umbraco.cms.businesslogic.datatype;
using umbraco;

namespace Umb.SimpleWebsite.Shared.DataTypes.SingleItemPicker
{
    public class PropertyPreValues:BaseFTypePreValueEditor
    {
        public PropertyPreValues(BaseDataType dataType,string FieldIdentifier):base(dataType,FieldIdentifier){}

        public override void ShowAdditionalFunctionality(string TextControlId)
        {//why here??? 
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<script type=\"text/javascript\" language=\"javascript\">");
            sb.AppendLine("  jQuery(document).ready(function(){");
            sb.AppendLine("     var cdp=new ISM_SimpleItemPickerPreValue('" + TextControlId + "',{ labels:['" + ui.Text("dataBaseDatatype") + "','" + ui.Text("IsmSingleItemPicker_StartFrom") + "']});");
            sb.AppendLine("     cdp.show();");
            sb.AppendLine("  })");
            sb.AppendLine("</script>");            

            LiteralControl lc = new LiteralControl(); lc.ID = this.ID + "_ld";
            lc.Text = sb.ToString();
            this.Controls.Add(lc);
        }

        public PreValueValue ValueObject
        {
            get {
                PreValue pv = this.PreValue;
                if (this.PreValue != null)
                {
                    System.Web.Script.Serialization.JavaScriptSerializer ser = new System.Web.Script.Serialization.JavaScriptSerializer();
                    PreValueValue result = (PreValueValue)ser.Deserialize(this.PreValue.Value, typeof(PreValueValue));
                    return result;
                }
                else return null;
            }
            //set{}
        }

        public class PreValueValue
        {
            public class PickerValue
            {
                public string name { get; set; }
                public string text { get; set; }               
            }
            public class Picker
            {
                public string name { get; set; }
                public string start { get; set; }
                public PickerValue value{ get; set; }
            }
            public string current { get; set; }
            public Picker[] pickers { get; set; }
        }
       
    }

}
